#include "managerWidget.h"
#include "ui_managerWidget.h"
#include "manager.h"

managerWidget::managerWidget(const QString name,QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::managerWidget)
    , name(name)
{
    ui->setupUi(this);
}

managerWidget::~managerWidget()
{
    delete ui;
}

void managerWidget::on_queryname_clicked()
{
    ui->result->clear();
    QString name=ui->name->text();
    manager m(this->name);
    try{
        QString line=m.queryName(name);
        ui->result->append(line);
    }catch(const QString& ex){
        ui->result->append(ex);
    }
}


void managerWidget::on_queryprice_clicked()
{
    ui->result->clear();
    QString minprice = ui->minprice->text();
    QString maxprice = ui->maxprice->text();
    manager m(name);
    try{
        QStringList lines = m.queryPrice(minprice.toDouble(), maxprice.toDouble());

        for (int i = 0; i < lines.size(); i++) {
            QString line = lines[i];
            ui->result->append(line);
        }
    }catch(const QStringList &e){
        ui->result->append("该价格区间菜单为空！请检查！");
    }
}



void managerWidget::on_querypopular_clicked()
{
    ui->result->clear();
    manager m(name);
    try{
        QString name=m.queryPopular();
        ui->result->append(name);
    }catch(const QString& ex){
        ui->result->append(ex);
    }

}


void managerWidget::on_queryall_clicked()
{
    ui->result->clear();
    manager m(name);
    QStringList lines = m.queryAll();

    for (int i = 0; i < lines.size(); i++) {
        QString line = lines[i];
        ui->result->append(line);
    }
}


void managerWidget::on_addtion_clicked()
{
    QString name=ui->name_2->text();
    QString type=ui->type->text();
    double price=ui->price->text().toDouble();
    manager m(name);
    try{
        m.sortInsert(name,type,price);
        QMessageBox::information(this, "提示", "操作成功！");
    }catch(const QString &e){
        QMessageBox::warning(this, "警告", e);
    }
}

